package org.freez4.spring.bean.factory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 默认UserFactory实现。
 * <pre>
 *
 * Bean 初始化
 * {@link PostConstruct}
 * {@link PreDestroy}
 * {@link InitializingBean#afterPropertiesSet()}
 * {@link DisposableBean#destroy()}
 * </pre>
 *
 * @author 阿坤同学
 * @date 2023/12/6 4:28 PM
 */
public class DefaultUserFactory implements UserFactory, InitializingBean, DisposableBean {

    private static final Logger logger = Logger.getLogger(DefaultUserFactory.class.getName());

    @PostConstruct
    public void init() {
        logger.log(Level.INFO, () -> "@PostConstruct : UserFactory 初始化中...");
    }

    public void initUserFactory() {
        logger.log(Level.INFO, () -> "自定义初始化方法 initUserFactory() : UserFactory 初始化中...");
    }

    public void doDestroy() {
        logger.log(Level.INFO, () -> "自定义销毁方法 doDestroy() : UserFactory 销毁中...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        logger.log(Level.INFO, () -> "InitializingBean#afterPropertiesSet() : UserFactory 初始化中...");
    }

    @PreDestroy
    public void preDestroy() {
        logger.log(Level.INFO, () -> "@PreDestroy : UserFactory 销毁中...");
    }

    @Override
    public void destroy() throws Exception {
        logger.log(Level.INFO, () -> "DisposableBean#destroy() : UserFactory 销毁中...");
    }

}
